<template>
    <h2>注册页面</h2>
<table border="1">
    <tr>
        <td>用户名</td>
        <td><input type="text" v-model="info.ULname" /></td>
    </tr>
    <tr>
        <td>密码</td>
        <td><input type="password" v-model="info.ULpwd"/></td>
    </tr>
    <tr>
        <td colspan="2">
            <button @click="Register">注册</button>
        </td>
    </tr>
</table>
</template>
<script setup lang="ts">
import axios from 'axios';
import { ref} from'vue'
import {useRouter} from 'vue-router'
const router=useRouter()
const info = ref({
    ULname:'',
    ULpwd:''
})
const Register=()=>{
if(info.value.ULpwd==""){
    alert("密码不能为空")
    return
}

    axios.post('https://localhost:44396/api/User/UserRegister',
        {
            ULname:info.value.ULname,
            ULpwd:info.value.ULpwd
        }
    ).then(res=>{
        if(res.data==-1){
            alert('用户名已存在')
        }else if(res.data>0){
            alert('注册成功')
            router.push('/Ulogin')
        }
        else{
            alert("注册失败")
        }
    }).catch(err=>{
        console.log(err)
    })
}



</script>